package com.hongdee.rbac.oil.controller;

import com.hongdee.rbac.oil.entity.TBcOilEntity;
import com.hongdee.rbac.oil.service.ITBcOilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Liu XiaoLong
 * Date: 2018/1/22.
 * Remark:
 */
@RestController
@RequestMapping("/oil")
public class TBcOilController {

    @Autowired
    private ITBcOilService itBcOilService;

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Map saveOrUpdate(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestBody TBcOilEntity data) throws Exception {

        Map map = itBcOilService.add(data,uid);
        //map.put("success", true);
        map.put("msg", "保存成功");
        return map;
    }

    /**
     * @Name: 分页查询
     * @Author: Liu XiaoLong
     * @Date: 2018/1/22 17:14
     * @Remark:
     */
    @RequestMapping("/page")
    @ResponseBody
    public Map page(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "start", defaultValue = "0") String start,
                    @RequestParam(name = "limit", defaultValue = "50") String limit,
                    @RequestParam(name = "level", defaultValue = "") String level,
                    @RequestParam(name = "pId", defaultValue = "") String pId) throws Exception {

        Map map = itBcOilService.page(uid,start,limit,level,pId);
        map.put("msg", "保存成功");
        map.put("success", true);
        return map;
    }
/**
 * @Name: 获取资源树
 * @Author: Liu XiaoLong
 * @Date: 2018/1/23 10:30
 * @Remark:
 */
    @RequestMapping("/getDataTree")
    @ResponseBody
    public Map getDataTree(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token ) throws Exception {

        Map map = itBcOilService.getDataTree(uid);
        map.put("msg", "查询成功");
        map.put("success", true);
        return map;
    }
/**
 * @Name: 获取单条信息
 * @Author: Liu XiaoLong
 * @Date: 2018/1/23 17:16
 * @Remark:
 */
    @RequestMapping("/info")
    @ResponseBody
    public Map info(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "id", defaultValue = "") String id) throws Exception {

        Map map = itBcOilService.Info(uid,id);
        map.put("msg", "查询成功");
        map.put("success", true);
        return map;
    }
/**
 * @Name: 删除组或组下的所有数据
 * @Author: Liu XiaoLong
 * @Date: 2018/1/23 19:30
 * @Remark:
 */
    @RequestMapping("/deleteGroup")
    @ResponseBody
    public Map deleteGroup(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "id", defaultValue = "") String id,
                    @RequestParam(name = "level", defaultValue = "") String level) throws Exception {

        Map map = itBcOilService.deleteGroup(uid,id,level);
        return map;
    }

    /**
     * @Name: 更新分组及组下的所有内容
     * @Author: Liu XiaoLong
     * @Date: 2018/1/24 09:17
     * @Remark:
     */
    @RequestMapping("/updateGroup")
    @ResponseBody
    public Map updateGroup(@RequestParam(name = "uid", defaultValue = "") String uid,
                           @RequestParam(name = "token", defaultValue = "") String token,
                           @RequestParam(name = "id", defaultValue = "") String id,
                           @RequestBody TBcOilEntity tBcOilEntity) throws Exception {

        Map map = itBcOilService.updateGroup(uid,tBcOilEntity);
        return map;
    }




}
